package com.mall.model.vo;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

/**
 * @author : xyiaao
 * @createDate : 2022/3/30 9:22
 */
@Data
@NoArgsConstructor
public class CommonPage<T> implements Serializable {

    /**
     * 数据
     */
    private List<T> list;

    /**
     * 当前页
     */
    private Integer pageNum;

    /**
     * 每页大小
     */
    private Integer pageSize;

    /**
     * 总数
     */
    private Long total;

    /**
     * 总页数
     */
    private Integer totalPage;


    /**
     * 将mybatis-plus分页类型转为CommonPage
     *
     * @param pageInfo
     */
    public CommonPage(Page<T> pageInfo) {

        this.list = pageInfo.getRecords();
        this.pageNum = Math.toIntExact(pageInfo.getCurrent());
        this.pageSize = Math.toIntExact(pageInfo.getSize());
        this.total = pageInfo.getTotal();
        this.totalPage = Math.toIntExact(pageInfo.getPages());
    }

}
